package com.jr.service.impl;

import com.jr.dao.impl.EnterpriseDaoImpl;
import com.jr.dao.impl.SupplierWhiteListDaoImpl;
import com.jr.dao.impl.UserDaoImpl;
import com.jr.entry.Enterprise;
import com.jr.entry.SupplierWhiteList;
import com.jr.entry.User;
import com.jr.pojo.AddSupplierWhiteList;
import com.jr.pojo.InformationInWhiteMess;
import com.jr.service.SupplierWhiteListService;
import com.jr.util.WhitePageHelper;

import java.util.ArrayList;

public class SupplierWhiteListImpl implements SupplierWhiteListService {
    User user = new User();
    UserDaoImpl userDao = new UserDaoImpl();
    EnterpriseDaoImpl enterpriseDao = new EnterpriseDaoImpl();
    SupplierWhiteListDaoImpl supplierWhiteListDao = new SupplierWhiteListDaoImpl();
    Enterprise enterprise = new Enterprise();


    @Override
    public ArrayList<InformationInWhiteMess> selectAllMess(String account, String name, String level, WhitePageHelper whitePageHelper) {

       return supplierWhiteListDao.selectSupplierWhiteListByAccount(account, level, name,whitePageHelper);
    }


    @Override
    public boolean insertSupplierWhiteList(String account, String enterpriseName, String level) {
        SupplierWhiteList supplierWhiteList = new SupplierWhiteList();
        supplierWhiteList.setSupplierLevel(level);
        enterprise =  enterpriseDao.selectEnterpriseByAccount(account);
         Enterprise  enterprise1 = enterpriseDao.selectEnterpriseByName(enterpriseName);
        supplierWhiteList.setEnterpriseId(enterprise.getId());
        supplierWhiteList.setSupplierId(enterprise1.getId());
        return supplierWhiteListDao.insertSupplierWhiteList(supplierWhiteList);
    }

    @Override
    public boolean deleteSupplierWhiteList(String account, String enterpriseName) {
       enterprise =  enterpriseDao.selectEnterpriseByAccount(account);
        Enterprise  enterprise1 = enterpriseDao.selectEnterpriseByName(enterpriseName);
        return   supplierWhiteListDao.deleteSupplierWhiteListByEnterpriseIdAndSupplierId( Integer.toString(enterprise.getId()) ,Integer.toString(enterprise1.getId()) );

    }

    @Override
    public boolean updateSupplierWhiteList(String level, String account, String name) {
        return supplierWhiteListDao.updateSupplierWhiteListLevel(level,account,name);
    }

    @Override
    public ArrayList<AddSupplierWhiteList> selectSupplier(String account) {
      return   supplierWhiteListDao.selectSupplier(account);
    }

    @Override
    public int selectSize(String account, String level, String name) {
        return supplierWhiteListDao.selectSize(account,level,name);
    }
}
